package com.econorma.web;

import java.net.URL;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
 
 
public class JspPages {
	
	private static final int DEFAULT_PORT = 6161;

	private static Server server;
	
	final static String WEBAPPDIR = "com/resources/jsp";
	final static String CONTEXTPATH = "/jsp";
	
	 public static void main(String[] args) throws InterruptedException {
		 
			server = new Server(DEFAULT_PORT);
			start();
		 
	 }

		public static boolean start() {
			try {
			  
				ServletContextHandler context = new ServletContextHandler(
						ServletContextHandler.SESSIONS);
				context.addServlet(new ServletHolder(new FileServlet()), "/file/*");
				context.addServlet(new ServletHolder(new MapServlet()), "/map/*");
 				context.setContextPath("/");
				
				URL warUrl = JspPages.class.getClassLoader().getResource(WEBAPPDIR);
				final String warUrlString = warUrl.toExternalForm();
				WebAppContext webapp = new WebAppContext(warUrlString, CONTEXTPATH);
				 
			 
				ContextHandlerCollection contexts = new ContextHandlerCollection();
		        contexts.setHandlers(new Handler[] { context, webapp });
		 
		        server.setHandler(contexts);
			      
				server.start();

				
				return true;
			} catch (Exception e) {
				  e.printStackTrace(System.out);
				return false;
			}
		}
	
	
}
